<?php

namespace app\admin\controller;

use app\common\lib\Util;
use app\common\model\OpinionFeedback as feedBack;
use think\Request;

class OpinionFeedback extends Base
{
   public function index(feedBack $feedback){
       $opinionList = $feedback::with(['user.profile'])->paginate(15);
       $this->assign('title', '意见反馈');
       $this->assign('list', $opinionList);
       return $this->fetch();
   }

   public function detail(Request $request,feedBack $feedback){

       $id = $request->param('id/d');
       $opinionDetail = $feedback::with(['user.profile'])->where(['id'=>$id])->find();
       //dump($opinionDetail);
       if($opinionDetail){
          switch ($opinionDetail['back_type']){
              case 1:
                    $opinionDetail['back_type'] = '用户端';
                    break;
              case 2:
                  $opinionDetail['back_type'] = '跑男端';
                  break;
              default:
                  $opinionDetail['back_type'] = '未知';
                  break;
          }
           $create_time = date('Y-m-d H:i:s',$opinionDetail['create_time']);
           $opinionDetail['create_at'] = $create_time;
           $img_url = json_decode($opinionDetail['img_url'],true);
           if(is_array($img_url)&&count($img_url)>0){
               foreach ($img_url as &$v){
                   $v = 'http://'.$_SERVER['SERVER_NAME'].$v;
               }
           }
           $opinionDetail['img_url'] = $img_url;
        }

       return Util::apiResponse($opinionDetail,'',1);
   }
}
